home *** CD-ROM | disk | FTP | other *** search
/ Aminet 15 / Aminet 15 - Nov 1996.iso / Aminet / dev / misc / libx11.lha / libX11 / xtoolkit.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-09-22  |  29.7 KB  |  1,147 lines

  1. /* Copyright (c) 1996 by Terje Pedersen.  All Rights Reserved   */
  2. /*                                                              */
  3. /* By using this code you will agree to these terms:            */
  4. /*                                                              */
  5. /* 1. You may not use this code for profit in any way or form   */
  6. /*    unless an agreement with the author has been reached.     */
  7. /*                                                              */
  8. /* 2. The author is not responsible for any damages caused by   */
  9. /*    the use of this code.                                     */
  10. /*                                                              */
  11. /* 3. All modifications are to be released to the public.       */
  12. /*                                                              */
  13. /* Thats it! Have fun!                                          */
  14. /* TP                                                           */
  15. /*                                                              */
  16.  
  17. /***
  18.    NAME
  19.      Xtoolkit
  20.    PURPOSE
  21.      Xtoolkit functions to libX11
  22.    NOTES
  23.      
  24.    HISTORY
  25.      Terje Pedersen - Oct 23, 1994: Created.
  26. ***/
  27.  
  28. #include <intuition/intuition.h>
  29. #include <intuition/intuitionbase.h>
  30.  
  31. #include <graphics/gfx.h>
  32. #include <graphics/gfxbase.h>
  33. #include <graphics/gfxmacros.h>
  34. #include <graphics/displayinfo.h>
  35. #include <devices/timer.h>
  36.  
  37. #include <proto/intuition.h>
  38. #include <proto/graphics.h>
  39. #include <proto/gadtools.h>
  40. #include <proto/layers.h>
  41.  
  42. #include <assert.h>
  43. #include <dos.h>
  44. #include <signal.h>
  45. #include <stdlib.h>
  46. #include <string.h>
  47. #include <ctype.h>
  48. #include <varargs.h>
  49. #include <time.h>
  50. #include <stdio.h>
  51.  
  52. #include "libX11.h"
  53.  
  54. #define XLIB_ILLEGAL_ACCESS 1
  55.  
  56. #include <X11/X.h>
  57. #include <X11/Xlib.h>
  58. #include <X11/Xutil.h>
  59. #include <X11/Intrinsic.h>
  60. #include <X11/IntrinsicP.h>
  61. #include <X11/Core.h>
  62. #include <X11/CoreP.h>
  63. #include <X11/StringDefs.h>
  64.  
  65. #include <X11/Xm/XmStrDefs.h>
  66.  
  67. #include <libraries/mui.h>
  68. #include <proto/muimaster.h>
  69.  
  70. #include "amigax_proto.h"
  71. #include "amiga_x.h"
  72.  
  73. #include "resource_list.h"
  74. #undef memset
  75.  
  76. /*******************************************************************************************/
  77. /* external */
  78. extern char lookup_key(char *key);
  79. extern ULONG fwindowsig;
  80. extern int amiga_id,amiga_ham8,askmode;
  81. extern Display amigaX_display;
  82. extern Screen  amiga_screen[];
  83. extern Visual  amiga_visual;
  84. extern struct DosLibrary *DOSBase;
  85.  
  86. extern int gettimeofday(struct timeval *tp,struct timezone *tzp);
  87.  
  88. /*******************************************************************************************/
  89. /* internal */
  90.  
  91. static XtActionProc buttonfunc=0,buttonfunckey[6];
  92. static XtActionProc keyup=0;
  93. static XtActionList amiga_actions;
  94. static Cardinal amiga_num_actions=0;
  95. static int curevent=0;
  96. static int amiga_wait=0;
  97. static int num_amiga_keys=0;
  98. static unsigned long amiga_interval=0;
  99. static char proctype[20];
  100.  
  101. Pixmap amiga_bitmap;
  102.  
  103. extern String *_XtFallbackResource;
  104.  
  105. typedef struct _TimerEventRec {
  106.         struct timeval        te_timer_value;
  107.     struct _TimerEventRec *te_next;
  108.     Display              *te_dpy;
  109.     XtTimerCallbackProc   te_proc;
  110.     XtAppContext          app;
  111.     XtPointer          te_closure;
  112. } TimerEventRec;
  113.  
  114. static TimerEventRec Xevs[20];
  115. static XtTimerCallbackProc procs[20];
  116. static XtPointer datas[20];
  117. static ULONG Xt_interval[20];
  118.  
  119. typedef struct {
  120.   int key;
  121.   XtActionProc proc;
  122. }  amiga_table;
  123.  
  124. static amiga_table akeys[40];
  125.  
  126. XtAppContext  amiga_Context;
  127. Display       *amiga_Disp;
  128. struct _WidgetRec amigaWG;
  129. struct _WidgetRec *a_wid;
  130. struct _WidgetRec *app_wg;
  131.  
  132. static XEvent event;
  133.  
  134. static char applicationname[40];
  135.  
  136. /*******************************************************************************************/
  137. /*
  138. ULONG askscreenmode(void);
  139.  
  140. ULONG askscreenmode(){
  141.   struct ScreenModeRequester *modereq;
  142.   if(!(modereq =
  143.        AllocAslRequestTags(ASL_ScreenModeRequest,ASLSM_DoDepth,TRUE,ASLSM_DoHeight,TRUE,ASLSM_DoWidth,TRUE,ASLSM_DoOverscanType,TRUE,ASLSM_DoAutoScroll,TRUE,/*ASLSM_TitleText,title,*/ASLSM_InitialTopEdge,0,ASLSM_InitialHeight,512,ASLSM_InitialDisplayDepth,DG.nDisplayDepth,ASLSM_InitialDisplayWidth,DG.nDisplayWidth,ASLSM_InitialDisplayHeight,DG.nDisplayHeight,ASLSM_InitialDisplayID,amiga_id,/*ASLSM_Window,wnd,*/TAG_DONE))){
  144.     return(0);
  145.   }
  146.   if(!modereq) return(0);
  147.   else AslRequest (modereq,0L);
  148.   amiga_id=modereq->sm_DisplayID;
  149.   DG.nDisplayDepth=modereq->sm_DisplayDepth;
  150.   if(DG.nDisplayDepth>DG.nDisplayMaxDepth) DG.nDisplayMaxDepth=DG.nDisplayDepth;
  151.   if(modereq->sm_DisplayWidth>DG.nDisplayMaxWidth) DG.nDisplayMaxWidth=modereq->sm_DisplayWidth;
  152.   if(modereq->sm_DisplayHeight>DG.nDisplayMaxHeight) DG.nDisplayMaxHeight=modereq->sm_DisplayHeight;
  153.  
  154.   FreeAslRequest (modereq);
  155.   return((ULONG)amiga_id);
  156. }
  157. */
  158. XtShellStrings(){
  159. #ifdef DEBUGXEMUL_ENTRY
  160.   printf("XtShellStrings\n");
  161. #endif
  162.   return(0);
  163. }
  164.  
  165. void __stdargs _XtCheckSubclass(w, object_class, message)
  166.      Widget w;
  167.      WidgetClass object_class;
  168.      String message;
  169. {
  170. }
  171.  
  172.  
  173. Boolean _XtCheckSubclassFlag(w, object)
  174.      Widget w;
  175.      _XtXtEnum object;
  176. {
  177.   return FALSE;
  178. }
  179.  
  180. #undef XtWindow
  181. Window XtWindow(Widget w){
  182.   return((((struct _WidgetRec*)w)->core.window));
  183. }
  184.  
  185. int X11addresources(XrmOptionDescRec *options,Cardinal num_options,int *argc,String *argv,char *class)
  186. {
  187.   int i,a,found=0;
  188.   XrmValue value;
  189.   XrmDatabase db;
  190.   db=XtDatabase(amiga_Disp);
  191.   for(a=0;a<*argc;a++){
  192.     for(i=0;i<num_options;i++){
  193.       if(strcmp(argv[a],options[i].option)==0){
  194.     char tempname[120];
  195.     strcpy(tempname,applicationname);
  196.     strcat(tempname,options[i].specifier);
  197.     if(!(options[i].argKind==XrmoptionNoArg)){
  198.       if(a==*argc-1) printf("missing argument!\n");
  199.       else{
  200.         value.addr=argv[++a];
  201.         XrmPutResource(&db,tempname,(char const*)options[i].argKind,&value);
  202.         found++;
  203.       }
  204.     }
  205.     else{
  206.       value.addr=options[i].value;
  207.       XrmPutResource(&db,tempname,(char const*)options[i].argKind,&value);
  208.     }
  209.     found++;
  210.       }
  211.     }
  212.   }
  213.   {
  214.     extern XrmDatabase X11DefaultResources;
  215.     X11DefaultResources=db;
  216.   }
  217.   *argc-=found;
  218.   for(i=0;i<*argc;i++)
  219.     argv[i]=argv[found+i];
  220. }
  221.  
  222. Display *XtOpenDisplay(app_context, display_name, application_name,
  223.                application_class, options, num_options, argc, argv)
  224.      XtAppContext app_context;
  225.      _Xconst _XtString display_name;
  226.      _Xconst _XtString application_name;
  227.      _Xconst _XtString application_class;
  228.      XrmOptionDescRec *options;
  229.      Cardinal num_options;
  230.      int *argc;         /* was Cardinal * in Release 4 */
  231.      String *argv;
  232. {
  233. #ifdef DEBUGXEMUL_ENTRY
  234.   printf("(Xtoolkit)XtOpenDisplay\n");
  235. #endif
  236.   amiga_Disp=XOpenDisplay(display_name);
  237. #ifdef MUIAPP
  238.   X11mui_init();
  239. #endif
  240.   return(amiga_Disp);
  241. }
  242.  
  243. Object *X11appobj,*X11appwin,*X11appgrp,*X11menustrip;
  244.  
  245. void XtCloseDisplay(display)
  246.      Display *display;
  247. {
  248. #ifdef DEBUGXEMUL_ENTRY
  249.   printf("(Xtoolkit)XtCloseDisplay\n");
  250. #endif
  251. #ifdef XMUIAPP 
  252.   MUI_DisposeObject(X11appobj);
  253.   X11mui_cleanup();
  254. #endif
  255.   XCloseDisplay(display);
  256.   return;
  257. }
  258.  
  259. XtActionProc lookup_func(char *func){
  260.   int i;
  261.   for(i=0;amiga_num_actions;i++)
  262.     if(strcmp(func,amiga_actions[i].string)==0)
  263.       return(amiga_actions[i].proc);
  264.   return(NULL);
  265. }
  266.  
  267. ParseKeys(table)
  268.      _Xconst _XtString table;
  269. {
  270.   char *p=strstr(table,"<Key>");
  271.   while(p){
  272.     char *q,*r;
  273.     char key[20],func[40];
  274.     p=p+5;
  275.     q=strchr(p,':');
  276.     *q++=0;
  277.     strcpy(key,p);
  278.     r=strchr(q,'(');
  279.     *r=0;
  280.     q=strrchr(q,'\t');
  281.     *q++=0;
  282.     strcpy(func,q);
  283.     p=strstr(r+1,"<Key>");
  284.     if(num_amiga_keys<40){
  285.       akeys[num_amiga_keys].proc=lookup_func(func);
  286.       if(strlen(key)==1) akeys[num_amiga_keys].key=key[0];
  287.       else akeys[num_amiga_keys].key=lookup_key(key);
  288. /*      printf("(Xtoolkit)key [%s] func [%s] [%d]\n",key,func,akeys[num_amiga_keys].proc);*/
  289.       num_amiga_keys++;
  290.     } else printf("(Xtoolkit)actions overflow!\n");
  291.   }
  292. }
  293.  
  294. XtActionProc getfunc(char *ptr){
  295.   char *q=strchr(ptr,':')+1,*p;
  296.   XtActionProc func;
  297.   while(!isalpha(*q))q++;
  298.   if((p=strchr(q,'('))) *p=0;
  299.   func=lookup_func(q);
  300.   if(p) *p='(';
  301.   return(func);
  302. }
  303.  
  304. XtTranslations XtParseTranslationTable(table)
  305.      _Xconst _XtString table;
  306. {
  307.   char *ptr;
  308. #ifdef DEBUGXEMUL_ENTRY
  309.   printf("(Xtoolkit)XtParseTranslationTable\n");
  310. #endif
  311.  
  312.   if(strstr(table,"<Key>")) ParseKeys(table);
  313.   if((ptr=strstr(table,"<ButtonPress>"))){
  314.     buttonfunc=getfunc(ptr);
  315.   }
  316.   if((ptr=strstr(table,"<Btn1Down>"))) buttonfunckey[0]=getfunc(ptr);
  317.   if((ptr=strstr(table,"<Btn1Up>"))) buttonfunckey[1]=getfunc(ptr);
  318.   if((ptr=strstr(table,"<Btn2Down>"))) buttonfunckey[2]=getfunc(ptr);
  319.   if((ptr=strstr(table,"<Btn2Up>"))) buttonfunckey[3]=getfunc(ptr);
  320.   if((ptr=strstr(table,"<Btn3Down>"))) buttonfunckey[4]=getfunc(ptr);
  321.   if((ptr=strstr(table,"<Btn3Up>"))) buttonfunckey[5]=getfunc(ptr);
  322.  
  323.   if((ptr=strstr(table,"<KeyUp>"))){
  324.     keyup=getfunc(ptr);
  325.   }
  326.   
  327.   return(0);
  328. }
  329.  
  330. void XtAppAddActions(app_context, actions, num_actions)
  331.      XtAppContext app_context;
  332.      XtActionList actions;
  333.      Cardinal num_actions;
  334. {
  335. #ifdef DEBUGXEMUL_ENTRY
  336.   printf("(Xtoolkit)XtAppAddActions\n");
  337. #endif
  338.   amiga_actions=actions;
  339.   amiga_num_actions=num_actions;
  340.   return;
  341. }
  342.  
  343. extern int get_intuievent(XEvent *event);
  344. struct timeval Xt_time[20],Xt_time2;
  345.  
  346. void XtAppNextEvent(app, xevent)
  347.     XtAppContext app;
  348.     XEvent *xevent;
  349. {
  350.   int i,gotone=0;
  351.   long t2;
  352.   xevent->type=0;
  353.   xevent->xkey.keycode=0;
  354.   gettimeofday(&Xt_time2,0);
  355.   t2=(long)(Xt_time2.tv_sec*1000+Xt_time2.tv_usec/1000);
  356.   while(get_intuievent(xevent)&&!gotone){
  357.     if(xevent->type==KeyPress){
  358.       char buf[20];
  359.       KeySym k;
  360.       XLookupString((XKeyEvent *)xevent,buf,20,&k,NULL);
  361.       if(!keyup){
  362. /*    printf("adding 0 key event %d\n",xevent->xbutton.button);*/
  363.     for(i=0;i<num_amiga_keys;i++)
  364.       if(buf[0]==akeys[i].key){
  365. /*        printf("adding key [%c]\n\n",buf[0]);*/
  366.         XtAppAddTimeOut(app,0,(XtTimerCallbackProc)akeys[i].proc,NULL);
  367.         proctype[curevent-1]=1;
  368.         gotone=1;
  369.         break;
  370.       }
  371.       }else{
  372. /*    printf("adding 1 key event %d\n",xevent->xbutton.button);*/
  373.     XtAppAddTimeOut(app,0,(XtTimerCallbackProc)keyup,&xevent->xkey);
  374.     gotone=1;
  375.     proctype[curevent-1]=1;
  376.       }
  377.     }else if(xevent->type==ButtonPress){
  378. /*      printf("adding mouse event %d\n",xevent->xbutton.button);*/
  379.       if(buttonfunc)
  380.     XtAppAddTimeOut(app,0,(XtTimerCallbackProc)buttonfunc,&xevent->xbutton);
  381.       else{
  382.     switch(xevent->xbutton.button){
  383.     case 1: 
  384.       XtAppAddTimeOut(app,0,(XtTimerCallbackProc)buttonfunckey[0],&xevent->xbutton);
  385.       break;
  386.     case 2: 
  387.       XtAppAddTimeOut(app,0,(XtTimerCallbackProc)buttonfunckey[2],&xevent->xbutton);
  388.       break;
  389.     case 3: 
  390.       XtAppAddTimeOut(app,0,(XtTimerCallbackProc)buttonfunckey[4],&xevent->xbutton);
  391.       break;
  392.     }
  393.       }
  394.       gotone=1;
  395.       proctype[curevent-1]=1;
  396.     }
  397.   }
  398.   amiga_wait=0;
  399.   if(curevent>0){
  400.     long t1;
  401.     int oldest=-1,i;
  402.     long oldesttime=Xt_time[curevent-1].tv_sec;
  403.     Widget w=NULL;
  404. nextev:
  405.     curevent--;
  406. /*    printf("events %d\n",curevent);*/
  407.     if(curevent>0){
  408.       for(i=0;i<=curevent;i++){
  409. /*    printf("testing %d %d\n",i,Xt_time[i].tv_sec);*/
  410.     if(Xt_time[i].tv_sec<oldesttime){ 
  411.       oldesttime=Xt_time[i].tv_sec; oldest=i;
  412. /*      printf("ok older!\n");*/
  413.     }
  414.       }
  415.       if(oldest!=-1){
  416.     XtTimerCallbackProc p;
  417.     XtPointer d;
  418.     struct timeval t;
  419. /*    printf("not last (i %d last %d)!\n",oldest,curevent);*/
  420.     p=procs[curevent];   procs[curevent]=procs[oldest];     procs[oldest]=p;
  421.     d=datas[curevent];   datas[curevent]=datas[oldest];     datas[oldest]=d;
  422.     t=Xt_time[curevent]; Xt_time[curevent]=Xt_time[oldest]; Xt_time[oldest]=t;
  423.       }
  424.     }
  425.     t1=(long)(Xt_time[curevent].tv_sec*1000+Xt_time[curevent].tv_usec/1000);
  426.     /*    printf("diff %d interval %d delaying %d\n",t2-t1,Xt_interval[curevent],
  427.       Xt_interval[curevent]-(t2-t1));*/
  428.     if(t2-t1<Xt_interval[curevent]){
  429.       long d=(int)((Xt_interval[curevent]-(t2-t1))/*/20*/);
  430.       if(d>1){
  431.     X11delayfor(d);
  432.       }
  433. /*      else printf("delay %d ?\n",d);*/
  434.     }
  435.     if(!procs[curevent]){
  436. /*
  437.       printf("fatal error! can't call 0 !\n");
  438.       getchar();
  439. */
  440.       if(curevent>0) goto nextev;
  441.       else return;
  442.     }
  443.     if(proctype[curevent]){
  444. /*      printf("calling type 1\n");*/
  445.       ((__stdargs XtActionProc)procs[curevent])(w,(XEvent *)datas[curevent],NULL,(Cardinal*)&amiga_interval);
  446.     }
  447.     else{
  448. /*      printf("calling type 2 (%d)\n",procs[curevent]);*/
  449.       ((__stdargs XtTimerCallbackProc)procs[curevent])((XtPointer)datas[curevent],(XtIntervalId*)&amiga_interval);
  450.     }
  451.   }else amiga_wait=1;
  452. }
  453.  
  454.  
  455. XtIntervalId XtAppAddTimeOut(app_context, interval, proc, client_data)
  456.      XtAppContext app_context;
  457.      unsigned long interval;
  458.      XtTimerCallbackProc proc;
  459.      XtPointer client_data;
  460. {
  461. #ifdef DEBUGXEMUL_ENTRY
  462.   printf("(Xtoolkit)XtAppAddTimeOut interval %d event no %d\n",interval,curevent);
  463. #endif
  464.   if(curevent<20){
  465. /*    printf("adding event %d %d\n",proc,client_data);*/
  466.     procs[curevent]=proc;
  467.     datas[curevent]=client_data;
  468.  
  469.     gettimeofday(&Xt_time[curevent],0);
  470. /*    printf("time %d\n",Xt_time[curevent].tv_sec);*/
  471.     Xt_interval[curevent]=interval;
  472. /*    printf("interval %d\n",interval);*/
  473.     proctype[curevent]=0;
  474.     curevent++;
  475.   } /* else printf("(Xtoolkit)event overflow!\n");*/
  476.   return(0);
  477. }
  478.  
  479. void XtAppMainLoop(app_context)
  480.      XtAppContext app_context;
  481. {
  482. /*
  483. #ifdef DEBUGXEMUL_ENTRY
  484.   printf("(Xtoolkit)XtAppMainLoop\n");
  485. #endif
  486. /* add the expose event */
  487.   XtAppAddTimeOut(app_context,0,(XtTimerCallbackProc)amiga_actions[0].proc,NULL);
  488.   memset(&event,0,sizeof(XEvent));
  489.   for (;;) {
  490.     XtAppNextEvent(app_context, &event);
  491. /*    XtDispatchEvent(&event);*/
  492.     if(amiga_wait){ Wait(fwindowsig); amiga_wait=0;}
  493.  
  494.   }
  495. */
  496.   ULONG sigs;
  497.   int running=1;
  498.  
  499.   set(X11appwin,MUIA_Window_Open,TRUE);
  500.   while (running){
  501.     int mui_input;
  502.     mui_input=DoMethod(X11appobj,MUIM_Application_Input,&sigs);
  503.     switch (mui_input){
  504.     case MUIV_Application_ReturnID_Quit: 
  505.       running=0;
  506.       break;
  507.     }
  508.     if (running && sigs) Wait(sigs);
  509.   }
  510.   set(X11appwin,MUIA_Window_Open,FALSE);
  511.   return;
  512. }
  513.  
  514. #ifndef MAKE_ID
  515. #define MAKE_ID(a,b,c,d) ((ULONG) (a)<<24 | (ULONG) (b)<<16 | (ULONG) (c)<<8 | (ULONG) (d))
  516. #endif
  517.  
  518. extern struct NewMenu MenuData1[];
  519. extern int wbapp;
  520.  
  521. #ifndef XTMUI
  522. Widget XtAppCreateShell(application_name, application_class,
  523.             widget_class, display, args, num_args)
  524.      _Xconst _XtString application_name;
  525.      _Xconst _XtString application_class;
  526.      WidgetClass widget_class;
  527.      Display *display;
  528.      ArgList args;
  529.      Cardinal num_args;
  530. {
  531.   Window newwin=0;
  532.   int i,gotsize=0;
  533. /*  Widget wid=(Widget)malloc(sizeof(Widget));*/
  534. #ifdef DEBUGXEMUL_ENTRY
  535.   printf("(Xtoolkit)XtAppCreateShell [%d]\n",sizeof(Arg));
  536. #endif
  537.  
  538.   a_wid=&amigaWG;
  539.   for(i=0;i<num_args;i++){
  540. /*    printf("(Xtoolkit)arg[%d] %s=%d\n",i,args[i].name,args[i].value);*/
  541.     if(!strcmp(args[i].name,"maxWidth")||!strcmp(args[i].name,"Width")){
  542.       gotsize=1;
  543.       DG.nDisplayWidth=(int)(args[i].value);
  544.     }else if(!strcmp(args[i].name,"maxHeight")||!strcmp(args[i].name,"Height")){
  545.       DG.nDisplayHeight=(int)(args[i].value);
  546.     }else if(strcmp(args[i].name,"depth")==0){
  547.       DG.nDisplayDepth=(int)(args[i].value);
  548.     }
  549.   }
  550.   if(DG.nDisplayWidth>1280) wbapp=1;
  551.   if(gotsize)
  552.     if(!wbapp){
  553.       ULONG id=0;
  554. /*      if(askmode) id=askscreenmode();*/
  555.       newwin=AmigaCreateWindow(DG.nDisplayWidth,DG.nDisplayHeight,DG.nDisplayDepth,0,id);
  556.       ((struct _WidgetRec*)a_wid)->core.window=newwin;
  557.     }
  558.   ((struct _WidgetRec*)a_wid)->core.screen=&amiga_screen[0];
  559.   ((struct _WidgetRec*)a_wid)->core.name=application_name;
  560.   XSelectInput (&amigaX_display, newwin, KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask);
  561. #ifdef XMUIAPP
  562.   {
  563.     Widget w;
  564.     X11appwin=WindowObject,
  565.       MUIA_Window_Title, "Application root",
  566.       MUIA_Window_ID, MAKE_ID('A', 'P', 'P', 'R'),
  567.       MUIA_Window_Menustrip, X11menustrip = MUI_MakeObject(MUIO_MenustripNM,MenuData1,0),
  568.       WindowContents, X11appgrp=GroupObject,
  569.       End,
  570.     End;
  571.  
  572.     X11appobj=ApplicationObject,
  573.       MUIA_Application_Author, "NONE",
  574.       MUIA_Application_Base, application_name,
  575.       MUIA_Application_Title, application_name,
  576.       MUIA_Application_Version, "$VER: 0.07 ",
  577.       MUIA_Application_Copyright, "libX11 generated",
  578.       MUIA_Application_Description, "Something cool..",
  579.     SubWindow, X11appwin,
  580.     End;
  581.     w=MakeWidget(NULL,X11appgrp);
  582.     w->core.screen=DefaultScreenOfDisplay(display);
  583.     w->core.window=X11NewMUI(X11appwin);
  584. /*    w->core.self=X11NewMUI(X11appobj);*/
  585.     DoMethod(X11appwin, MUIM_Notify, MUIA_Window_CloseRequest, TRUE, X11appobj, 2, MUIM_Application_ReturnID, MUIV_Application_ReturnID_Quit);
  586.     return(w);
  587.   }
  588. #else
  589.   return((struct _WidgetRec*)a_wid);
  590. #endif
  591. }
  592.  
  593. #endif
  594.  
  595. applicationShellWidgetClass(){
  596. #ifdef DEBUGXEMUL_ENTRY
  597.   printf("(Xtoolkit)applicationShellWidgetClass\n");
  598. #endif
  599.   return(0);
  600. }
  601.  
  602. char *dotdisp=".display";
  603. char *workbenchstr="Workbench";
  604. #ifndef XTMUI
  605.  
  606. Widget XtAppInitialize(app_context_return, application_class, options,
  607.                num_options, argc_in_out, argv_in_out, fallback_resources, args,
  608.                num_args)
  609.      XtAppContext *app_context_return;
  610.      _Xconst _XtString application_class;
  611.      XrmOptionDescList options;
  612.      Cardinal num_options;
  613.      int *argc_in_out;           /* was type Cardinal * in R4 */
  614.      String *argv_in_out;
  615.      String *fallback_resources;
  616.      ArgList args;
  617.      Cardinal num_args;
  618. {
  619.   int i,found=0;
  620.   XrmDatabase db;
  621.   XrmValue value;
  622.   char *display_name=NULL;
  623.   char appdisp[50];
  624. #ifdef DEBUGXEMUL_ENTRY
  625.   printf("(Xtoolkit)XtAppInitialize\n");
  626. #endif
  627.   XtToolkitInitialize();
  628.   XrmInitialize();
  629.   strcpy(applicationname,application_class /*argv_in_out[0]*/);
  630.   strcpy(appdisp,application_class);
  631.   strcat(appdisp,".display");
  632.   amiga_Context = XtCreateApplicationContext();
  633.  
  634.   _XtFallbackResource=fallback_resources;
  635.   db=XtDatabase(amiga_Disp);
  636.  
  637.   X11addresources(options,num_options,argc_in_out,argv_in_out,application_class);
  638.   db=XtDatabase(amiga_Disp);
  639.   if(!XrmGetResource(db,dotdisp,NULL,NULL,&value)){
  640.     value.addr=workbenchstr;
  641.     XrmPutResource(&db,dotdisp,NULL,&value);
  642.   }
  643.   for(i=1;i<*argc_in_out;i++){
  644.     if(XrmGetResource(db,argv_in_out[i],NULL,NULL,&value)){
  645.       argv_in_out[i][0]='.';
  646.       value.addr=argv_in_out[++i];
  647.       XrmPutResource(&db,argv_in_out[i-1],NULL,&value);
  648.       found+=2;
  649.     }
  650.   }
  651.   X11DefaultResources=db;
  652.   *argc_in_out-=found;
  653.   if(XrmGetResource(XtDatabase(&amigaX_display),appdisp,NULL,NULL,&value))
  654.     display_name=value.addr;
  655.   else
  656.     if(XrmGetResource(XtDatabase(&amigaX_display),dotdisp,NULL,NULL,&value))
  657.       display_name=value.addr;
  658.     
  659.   amiga_Disp = XtOpenDisplay(amiga_Context, display_name, application_class,NULL,options,num_options,argc_in_out,argv_in_out);
  660.   app_wg = XtAppCreateShell(application_class,application_class, 0 /*applicationShellWidgetClass*/, 
  661.                          amiga_Disp, args, num_args);
  662.   return(app_wg);
  663. }
  664.  
  665. #endif
  666.  
  667. void XtGetApplicationResources(object, base, resources, num_resources,
  668.                    args, num_args)
  669.      Widget object;
  670.      XtPointer base;
  671.      XtResourceList resources;
  672.      Cardinal num_resources;
  673.      ArgList args;
  674.      Cardinal num_args;
  675. {
  676.   XrmValue value;
  677.   XrmDatabase db;
  678.   int i,found;
  679.   void *addr;
  680.   char *appname,tempname[256];
  681. #ifdef DEBUGXEMUL_ENTRY
  682.   printf("XtGetApplicationResources [%s]\n",appname);
  683. #endif
  684.   XrmInitialize();
  685.   db=XtDatabase(amiga_Disp);
  686.   appname=((struct _WidgetRec*)object)->core.name;
  687.   for(i=0;i<num_resources;i++){
  688.     int immediate=0;
  689.     char *dest=(char*)base+resources[i].resource_offset;
  690.     found=0;
  691.     strcpy(tempname,appname);
  692.     strcat(tempname,".");
  693.     strcat(tempname,resources[i].resource_name);
  694.     if(strcmp(resources[i].default_type,XtRImmediate)==0) immediate=1;
  695. //    if(strcmp(resources[i].default_type,XtRBoolean)==0) immediate=1;
  696.     if(XrmGetResource(db,tempname,NULL,NULL,&value)){
  697.       addr=(void*)value.addr;
  698.       found=1;
  699. /*
  700.       immediate=1;
  701.       if(immediate){
  702. */
  703.     if(strcmp(resources[i].resource_type,"Int")==0)
  704.       *((int*)dest)=atoi((char*)addr);
  705.     else if(strcmp(resources[i].resource_type,"Boolean")==0){
  706.       if(stricmp((char*)addr,"False")==0||
  707.          stricmp((char*)addr,"No")==0) *((char*)(dest))=0;
  708.       else *((char*)(dest))=1;
  709.     } else if(strcmp(resources[i].resource_type,"String")==0){
  710.       *(int*)((char*)base+resources[i].resource_offset)=(int*)addr;
  711.     } else if(strcmp(resources[i].resource_type,XtRFloat)==0){
  712.       *((float*)((char*)base+resources[i].resource_offset))=atof((char const*)addr);
  713.     }
  714. /*
  715.       }else {
  716.     if(strcmp(resources[i].resource_type,"Int")==0)
  717.       *((int*)(dest))=*(int*)addr;
  718.     else if(strcmp(resources[i].resource_type,"Boolean")==0){
  719.       *((char*)(dest))=*(char*)addr;
  720.     } else if(strcmp(resources[i].resource_type,"String")==0){
  721.       *(int*)((char*)base+resources[i].resource_offset)=(int*)addr;
  722.     } else if(strcmp(resources[i].resource_type,XtRFloat)==0){
  723.       *((float*)((char*)base+resources[i].resource_offset))=*(float*)addr;
  724.     }
  725.       }
  726. */ 
  727.     }
  728.     else{
  729. /*      int data=0;*/
  730.       addr=(void*)resources[i].default_addr;
  731. /*      if(!addr && !immediate ) addr= &data;*/
  732.       if( immediate ){
  733.     if(strcmp(resources[i].resource_type,"Int")==0){
  734.       *((int*)((char*)base+resources[i].resource_offset))=(int)addr;
  735.     } else if(strcmp(resources[i].resource_type,"Boolean")==0){
  736.       *((char*)((char*)base+resources[i].resource_offset))=(char)addr;
  737.     } /* else if(strcmp(resources[i].resource_type,"String")==0){
  738.       *(int*)((char*)base+resources[i].resource_offset)=(int)addr;
  739.     } else if(strcmp(resources[i].resource_type,XtRFloat)==0){
  740.       *((float*)((char*)base+resources[i].resource_offset))=*(float*)addr;
  741.     }*/
  742.       } else {
  743.     if(strcmp(resources[i].resource_type,"Int")==0){
  744.       *((int*)((char*)base+resources[i].resource_offset))=*(int*)addr;
  745.     } else if(strcmp(resources[i].resource_type,"Boolean")==0){
  746.       *((char*)((char*)base+resources[i].resource_offset))=*(char*)addr;
  747.     } else if(strcmp(resources[i].resource_type,"String")==0){
  748.       *(int*)((char*)base+resources[i].resource_offset)=(int*)addr;
  749.     } else if(strcmp(resources[i].resource_type,XtRFloat)==0){
  750.       *((float*)((char*)base+resources[i].resource_offset))=*(float*)addr;
  751.     }
  752.       }     
  753.     }
  754.   }
  755.   return;
  756. }
  757.  
  758. Boolean XtDispatchEvent (event)
  759.     XEvent  *event;
  760. {
  761. #if (DEBUGXEMUL_ENTRY) || (DEBUGXEMUL_WARNING)
  762.   printf("WARNING: XtDispatchEvent\n");
  763. #endif
  764.   return(False);
  765. }
  766.  
  767. #ifndef XTMUI
  768. void XtRealizeWidget(w)
  769.      Widget w;
  770. {
  771.   LONG l;
  772. #ifdef XMUIAPP
  773.   assert(w);
  774.   get(X11DrawablesMUI[(XID)w->core.window],MUIA_Window_Open,&l);
  775.   if(!l)
  776.     set(X11DrawablesMUI[(XID)w->core.window],MUIA_Window_Open,TRUE);
  777. #else
  778.   XrmValue value;
  779.   extern int usewb;
  780.   extern struct Screen *Scr,*wb;
  781.   Window newwin;
  782. #ifdef DEBUGXEMUL_ENTRY
  783.   printf("XtRealizeWidget\n");
  784. #endif
  785.   usewb=1;wbapp=1;
  786.   Scr=wb;
  787.   X11init_cmaps();
  788.   newwin=AmigaCreateWindow(DG.nDisplayWidth,DG.nDisplayHeight,DG.nDisplayDepth,0,0);
  789.   ((struct _WidgetRec*)a_wid)->core.window=newwin;
  790.     
  791.   if(XrmGetResource(XtDatabase(&amigaX_display),".title",NULL,NULL,&value)){
  792.     XStoreName(&amigaX_display,newwin,value.addr);
  793.   }
  794.   return;
  795. #endif
  796. }
  797.  
  798. #endif
  799.  
  800. void XtToolkitInitialize(){
  801. #ifdef DEBUGXEMUL
  802.   printf("XtToolkitInitialize\n");
  803. #endif
  804.   return;
  805. }
  806.  
  807. XtAppContext XtCreateApplicationContext(){
  808. #ifdef DEBUGXEMUL
  809.   printf("XtCreateApplicationContext\n");
  810. #endif
  811.   return(0);
  812. }
  813.  
  814. XtStrings(){
  815. #ifdef DEBUGXEMUL
  816.   printf("XtStrings\n");
  817. #endif
  818.   return(0);
  819. }
  820.  
  821. void XtAddEventHandler(w, event_mask, nonmaskable, proc, client_data)
  822.      Widget w;
  823.      EventMask event_mask;
  824.      Boolean nonmaskable;
  825.      XtEventHandler proc;
  826.      XtPointer client_data;
  827. {/*       File 'xmgr.o'*/
  828. #ifdef DEBUGXEMUL
  829.   printf("XtAddEventHandler\n");
  830. #endif
  831.   return;
  832. }
  833.  
  834. void XtAddCallback(object, callback_name, callback, client_data)
  835.      Widget object;
  836.      _Xconst _XtString callback_name;
  837.      XtCallbackProc callback;
  838.      XtPointer client_data;
  839. {/*           File 'xmgr.o'*/
  840. #ifdef DEBUGXEMUL
  841.   printf("XtAddCallback\n");
  842. #endif
  843.   return;
  844. }
  845.  
  846. void XtAddGrab(w, exclusive, spring_loaded)
  847.      Widget w;
  848.      Boolean exclusive;
  849.      Boolean spring_loaded;
  850. {/*               File 'malerts.o'*/
  851. #ifdef DEBUGXEMUL
  852.   printf("XtAddGrab\n");
  853. #endif
  854.   return;
  855. }
  856.  
  857. XtInputMask XtAppPending(app_context)
  858.      XtAppContext app_context;
  859. {/*            File 'malerts.o'*/
  860. #ifdef DEBUGXEMUL
  861.   printf("XtAppPending\n");
  862. #endif
  863.   return(0);
  864. }
  865.  
  866. void XtAppProcessEvent(app_context, mask)
  867.      XtAppContext app_context;
  868.      XtInputMask mask;
  869. {/*       File 'motifutils.o'*/
  870. #ifdef DEBUGXEMUL
  871.   printf("XtAppProcessEvent\n");
  872. #endif
  873. }
  874.  
  875. void XtFree(ptr)
  876. char *ptr;
  877. {/*                  File 'fileswin.o'*/
  878. #ifdef DEBUGXEMUL
  879.   printf("XtFree\n");
  880. #endif
  881. }
  882.  
  883. void XtGetValues(wid, args, num_args)
  884.      Widget wid;
  885.      ArgList args;
  886.      Cardinal num_args;
  887. {/*             File 'events.o'*/
  888.   int i;
  889.   Object *obj;
  890.   XID object;
  891. #ifdef DEBUGXEMUL
  892.   printf("XtGetValues\n");
  893. #endif
  894.  
  895.   if(!wid) return;
  896.   object=(XID)wid->core.self;
  897.   if(X11Drawables[object]!=X11MUI) return;
  898.   obj=X11DrawablesMUI[X11DrawablesMap[object]];
  899.   for(i=0;i<num_args;i++){
  900.     unsigned short *ptr=(unsigned short*)(args[i].value);
  901. /*    printf("%d\n",args[i].value);*/
  902.     *ptr=0;
  903.     if(strcmp(args[i].name,XtNwidth)==0){
  904.       *ptr=(unsigned short)_mwidth(obj);
  905.     }else if(strcmp(args[i].name,XtNheight)==0){
  906.       *ptr=(unsigned short)_mheight(obj);
  907.     }
  908. /*    printf("value %s set to %d\n",args[i].name,*ptr);*/
  909.   }
  910. }
  911.  
  912. char *XtMalloc(size)
  913. Cardinal size;
  914. {/*                File 'helpwin.o'*/
  915. #ifdef DEBUGXEMUL
  916.   printf("XtMalloc\n");
  917. #endif
  918.   return((char*)malloc(size));
  919. }
  920.  
  921. void XtRemoveGrab(w)
  922.      Widget w;
  923. {/*            File 'malerts.o'*/
  924. #ifdef DEBUGXEMUL
  925.   printf("XtRemoveGrab\n");
  926. #endif
  927. }
  928.  
  929. void XtSetValues(object, args, num_args)
  930.      Widget object;
  931.      ArgList args;
  932.      Cardinal num_args;
  933. {
  934.   int i;
  935. #ifdef DEBUGXEMUL
  936.   printf("XtSetValues\n");
  937. #endif
  938.   return;
  939.  
  940.   for(i=0;i<num_args;i++){
  941.     if(strcmp(args[i].name,XtNwidth)==0){
  942.       DG.nDisplayWidth=args[i].value;
  943.     }else if(strcmp(args[i].name,XtNheight)==0){
  944.       DG.nDisplayHeight=args[i].value;
  945.     }else if(strcmp(args[i].name,XtNbackgroundPixmap)==0){
  946.       amiga_bitmap=args[i].value;
  947.     }
  948.   }
  949. }
  950.  
  951. Widget XtVaCreateManagedWidget(name, widget_class, parent,args,num_args)
  952.      _Xconst _XtString name;
  953.      WidgetClass widget_class;
  954.      Widget parent;
  955.      ArgList args;
  956.      Cardinal num_args;
  957. {/* File 'xmgr.o'*/
  958. #ifdef DEBUGXEMUL
  959.   printf("XtVaCreateManagedWidget\n");
  960. #endif
  961.   return(NULL);
  962. }
  963. Widget XtVaCreateWidget(name, object_class, parent,args,num_args)
  964.      _Xconst _XtString name;
  965.      WidgetClass object_class;
  966.      Widget parent;
  967.      ArgList args;
  968.      Cardinal num_args;
  969. {/*        File 'labelwin.o'*/
  970. #ifdef DEBUGXEMUL
  971.   printf("XtVaCreateWidget\n");
  972. #endif
  973.   return(0);
  974. }
  975.  
  976. void XtVaSetValues(Widget object,... )
  977. {
  978. /*
  979.   va_list arglist;
  980.   int count;
  981.   char *argstr;
  982.   int argval;
  983.   BOOL bGotOne=TRUE;
  984.   Object *obj;
  985.  
  986.   va_start(arglist,count);
  987.   
  988.   while(bGotOne){
  989.     argstr=va_arg(arglist,char *);
  990.     if(!argstr) bGotOne=FALSE;
  991.     else argval=va_arg(arglist,int);
  992.     if(!strcmp(argstr,XmNwidth)){
  993.       obj=X11DrawablesMUI[X11DrawablesMap[(XID)object->core.self]];
  994.       set(obj,MUIA_FixWidth,argval);
  995.     } else if(!strcmp(argstr,XmNheight)){
  996.       obj=X11DrawablesMUI[X11DrawablesMap[(XID)object->core.self]];
  997.       set(obj,MUIA_FixHeight,argval);
  998.     }
  999.   }
  1000. */
  1001. }
  1002.  
  1003. void XtWarning(message)
  1004.      _XtString message;
  1005. {/*               File 'xmgr.o'*/
  1006. #if (DEBUGXEMUL_ENTRY) || (DEBUGXEMUL_WARNING)
  1007.   printf("WARNING: XtWarning\n");
  1008. #endif
  1009. }
  1010.  
  1011. XtAppContext XtWidgetToApplicationContext(object)
  1012.      Widget object;
  1013. {/* File 'motifutils.o'*/
  1014. #if (DEBUGXEMUL_ENTRY) || (DEBUGXEMUL_WARNING)
  1015.   printf("WARNING: XtWidgetToApplicationContext\n");
  1016. #endif
  1017.   return(0);
  1018. }
  1019.  
  1020. #ifndef XTMUI
  1021. void XtDestroyWidget(object)
  1022.      Widget object;
  1023. {/*         File 'xdaliclock.o'*/
  1024. #if (DEBUGXEMUL_ENTRY) || (DEBUGXEMUL_WARNING)
  1025.   printf("WARNING: XtDestroyWidget\n");
  1026. #endif
  1027.   return;
  1028. }
  1029. #endif
  1030.  
  1031. void XtGetApplicationNameAndClass(display,name_return,class_return)
  1032.      Display *display;
  1033.      String  *name_return;
  1034.      String  *class_return;
  1035. {/* File 'xdaliclock.o'*/
  1036. #ifdef DEBUGXEMUL_ENTERY
  1037.   printf("XtGetApplicationNameAndClass\n");
  1038. #endif
  1039.   *name_return=applicationname;
  1040.   return;
  1041. }
  1042.  
  1043. #undef XtParent
  1044.  
  1045. Widget XtParent(Widget widget){
  1046.   if(widget) return(widget->core.parent);
  1047.   else return NULL;
  1048. }
  1049.  
  1050. #undef XtScreen
  1051.  
  1052. Screen *XtScreen(Widget widget){
  1053.   if(widget)return(widget->core.screen);
  1054.   else return NULL;
  1055. }
  1056.  
  1057. #undef XtDisplay
  1058.  
  1059. Display *XtDisplay(Widget widget){
  1060.   if(widget) return(DisplayOfScreen(widget->core.screen));
  1061.   else return NULL;
  1062. }
  1063.  
  1064.  
  1065. GC XtGetGC(object, value_mask, values)
  1066.      Widget object;
  1067.      XtGCMask value_mask;
  1068.      XGCValues *values;
  1069. {/*                 File 'xlogo.o'*/
  1070. #ifdef DEBUGXEMUL_ENTERY
  1071.   printf("XtGetGC\n");
  1072. #endif
  1073.   return(XCreateGC(NULL,NULL,value_mask,values));
  1074. }
  1075.  
  1076. /*
  1077. XtCreateManagedWidget(){/*   File 'xlogo.o'*/
  1078. #if (DEBUGXEMUL_ENTRY) || (DEBUGXEMUL_WARNING)
  1079.   printf("WARNING: XtCreateManagedWidget\n");
  1080. #endif
  1081.   return(0);
  1082. }
  1083.  
  1084. Widget XtInitialize(shell_name, application_class, options,
  1085.             num_options, argc, argv)
  1086.      String shell_name;    /* unused */
  1087.      String application_class;
  1088.      XrmOptionDescRec options[];
  1089.      Cardinal num_options;
  1090.      Cardinal *argc;
  1091.      char *argv[];
  1092.  
  1093. {/*            File 'xlogo.o'*/
  1094. #ifdef DEBUGXEMUL_ENTRY
  1095.   printf("XtInitialize\n");
  1096. #endif
  1097.   return(XtAppInitialize(NULL,application_class,options,num_options,NULL,NULL,NULL,NULL,NULL));
  1098. }
  1099.  
  1100. XtMainLoop(){/*              File 'xlogo.o'*/
  1101. #ifdef DEBUGXEMUL_ENTRY
  1102.   printf("XtMainLoop\n");
  1103. #endif
  1104.   XtAppMainLoop(amiga_Context);
  1105.   return(0);
  1106. }
  1107. */
  1108.  
  1109. Window XtWindowOfObject(object)
  1110.      Widget object;
  1111. {/*        File 'xlogo.o'*/
  1112. #if (DEBUGXEMUL_ENTRY) || (DEBUGXEMUL_WARNING)
  1113.   printf("WARNING: XtWindowOfObject\n");
  1114. #endif
  1115.   return(0);
  1116. }
  1117.  
  1118. XtInputId XtAppAddInput(app_context, source, condition, proc, client_data)
  1119.      XtAppContext app_context;
  1120.      int source;
  1121.      XtPointer condition;
  1122.      XtInputCallbackProc proc;
  1123.      XtPointer client_data;
  1124. {
  1125. #if (DEBUGXEMUL_ENTRY) || (DEBUGXEMUL_WARNING)
  1126.   printf("WARNING: XtAppAddInput\n");
  1127. #endif
  1128.   return (XtInputId)0;
  1129. }
  1130.  
  1131. void XtRemoveInput(id)
  1132.      XtInputId id;
  1133. {
  1134. #if (DEBUGXEMUL_ENTRY) || (DEBUGXEMUL_WARNING)
  1135.   printf("WARNING: XtRemoveInput\n");
  1136. #endif
  1137. }
  1138.  
  1139.  
  1140. void XtDestroyApplicationContext(app_context)
  1141.      XtAppContext app_context;
  1142. {
  1143. #if (DEBUGXEMUL_ENTRY) || (DEBUGXEMUL_WARNING)
  1144.   printf("WARNING: XtDestroyApplicationContext\n");
  1145. #endif
  1146. }
  1147.